﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Framework.Client;

namespace FunctionPoint.Common
{
    public class TfsUser : TfsSecurityObject, IComparable<TfsUser>
    {

        
        public TeamFoundationIdentity TeamFoundationIdentity
        {
            get;
            private set;
        }
        public IGroupSecurityService2 GroupSecurityService
        {
            get;
            private set;
        }
        public string AccountName
        {
            get
            {
                return Identity.AccountName;
            }
        }

        public string DisplayName
        {
            get
            {
                return Identity.DisplayName;
            }
        }

        public Identity Identity
        {
            get;
            private set;
        }

        public TfsUser(Identity identity, IGroupSecurityService2 groupSecurityService)
        {
            GroupSecurityService = groupSecurityService;
            Identity = identity;
            TeamFoundationIdentity = groupSecurityService.Convert(identity);

        }


        #region Comparable Methods

        public int CompareTo(TfsUser other)
        {
            return string.Compare(this.DisplayName, other.DisplayName);
        }
        
        #endregion
    }

    public class TfsUserEqualityComparer : IEqualityComparer<TfsUser>
    {

        public bool Equals(TfsUser x, TfsUser y)
        {
            return x.AccountName == y.AccountName;
        }

        public int GetHashCode(TfsUser obj)
        {
            return obj.GetHashCode();
        }
    }

}
